package com.print.ane.funs;

import java.io.File;

import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;

import com.adobe.fre.FREContext;
import com.adobe.fre.FREFunction;
import com.adobe.fre.FREObject;

public class PrintFile implements FREFunction {

	@Override
	public FREObject call(FREContext content, FREObject[] arg1) {
		String mete = null;
		String packet = null;
		String activity = null;
		String path = null;
		try{
			mete = arg1[0].getAsString();
			packet = arg1[1].getAsString();
			activity = arg1[2].getAsString();
			path = arg1[3].getAsString();
		}catch(Exception e){}
		
		
		//检查参数
		if(mete == null || path == null || packet == null){
			return null;
		}
		
		//检查文件存在
		File file = new File(path);
		if(!file.exists()){
			return null;
		}
		
		//打开打印
		Intent intent = new Intent();
		intent.setComponent(new ComponentName(packet, activity));
		intent.setAction("android.intent.action.VIEW");
		intent.setType(mete);
		intent.setData(Uri.fromFile(file));
		content.getActivity().startActivity(intent);
		try{
			return FREObject.newObject(true);
		}catch(Exception e){
			return null;
		}
	}

}
